package com.rory.gooday.index;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.json.Json;
import com.jfinal.plugin.redis.Redis;
import com.rory.gooday.common.GoodConfig;
import redis.clients.jedis.params.SetParams;

@Path(value = "/", viewPath = "/index")
public class IndexController extends Controller {
	public void index() {
 		render("index.html");
	}

	public void login() {
		render("login.html");
	}

    public void logout() {
        Redis.call(jedis -> {
            SetParams setParams = new SetParams();
            setParams.ex(GoodConfig.logoutime);
            return jedis.set("rory", "0",  setParams);
        });
        render("login.html");
    }

    public void loginto() {
        String uname = getPara("uname");
        String upwd = getPara("upwd");
        if("rory".equals(uname) && "123456".equals(upwd)){
            String sid = getSession().getId();
            Redis.call(jedis -> {
                SetParams setParams = new SetParams();
                setParams.ex(GoodConfig.logoutime);
                return jedis.set(uname, sid,  setParams);
            });
        }
        redirect("/");
    }
}



